package cn.itcast.babasport.controller.product;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import cn.itcast.babasport.pojo.page.Pagination;
import cn.itcast.babasport.pojo.product.Brand;
import cn.itcast.babasport.pojo.product.Color;
import cn.itcast.babasport.service.brand.BrandService;
import cn.itcast.babasport.service.color.ColorService;
import cn.itcast.babasport.service.product.ProductService;
import cn.itcast.babasport.service.upload.UploadService;
import cn.itcast.babasport.utils.constants.BbsConstants;

@Controller
@RequestMapping("/product")
public class ProductController {
	@Resource
	private ProductService productService;
	@Resource
	private BrandService brandService;
	@Resource
	private ColorService colorservice;
	
	
	/**
	 * 跳转商品页面
	 * @param name
	 * @param brandId
	 * @param isShow
	 * @param pageNo
	 * @param model
	 * @return
	 */
	@RequestMapping("/list.do")
	public String list(String name, Long brandId, Boolean isShow, Integer pageNo, Model model){
		//初始化品牌的下拉列表
		List<Brand> brands = brandService.selectBrandListNoPage(null, 1);
		model.addAttribute("brands", brands);
		//商品列表
		Pagination pagination = productService.selectProductListHavePage(name, brandId, isShow, pageNo);
		model.addAttribute("pagination", pagination);
		//查询条件回显
		model.addAttribute("name", name);
		model.addAttribute("brandId", brandId);
		model.addAttribute("isShow", isShow);
		model.addAttribute("pageNo", pageNo);
		
		return "product/list";
	}
	/**
	 * 跳转到商品添加页面
	 * @param name
	 * @param brandId
	 * @param isShow
	 * @param pageNo
	 * @param model
	 * @return
	 */
	@RequestMapping("/add.do")
	public String add( Model model){
		//初始化品牌信息
		List<Brand> brands = brandService.selectBrandListNoPage(null, 1)	;
		model.addAttribute("brands", brands);
		//初始化颜色信息
		List<Color> colors = colorservice.selectColorList();
		model.addAttribute("colors", colors);
		return "product/add";
	}
	
	

	
	
}
